﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace EquipmentManager
{
    // Примечание: Инструкции по включению классического режима IIS6 или IIS7 
    // см. по ссылке http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }

        /// <summary>
        /// Application_s the error.
        /// </summary>
        protected void Application_Error()
        {
            string action = "TechnicalError";
            Exception exception = Server.GetLastError();

            Response.Clear();

            HttpException httpException = exception as HttpException;

            if (httpException != null)
            {

                switch (httpException.GetHttpCode())
                {
                    case 404:
                        // page not found
                        action = "HttpError404";
                        break;
                    case 500:
                        // server error
                        action = "HttpError500";
                        break;
                }

                // clear error on server
                Server.ClearError();

            }

            Response.Redirect(String.Format("~/Error/{0}", action));
        }


        /// <summary>
        /// Handles the Start event of the Session control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /*void Session_Start(object sender, EventArgs e)
        {
            //TODO: add user info from session
            logger.Info(String.Format("Session Started. SessionId: {0}", HttpContext.Current.Session.SessionID));
        }*/

        /// <summary>
        /// Handles the End event of the Session control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        //void Session_End(object sender, EventArgs e)
        //{
        //    //TODO: add user info from session
        //    logger.Info(String.Format("Session Ended. SessionId: {0}", HttpContext.Current.Session.SessionID));
        //}
    }
}